package Server;

import java.net.ServerSocket;

import javax.swing.*;

import Server.SocketManager;

public class VentanaServidor extends JFrame {

	private static final long serialVersionUID = 1L;

	private ServerSocket welcomeSocket;

	public VentanaServidor(){


		this.setSize(750, 490);
		this.setTitle("Servidor");
		this.setResizable(false);
		this.setLocation((getToolkit().getScreenSize().width - this.getBounds().width) / 2,
				(getToolkit().getScreenSize().height - this.getBounds().height) / 2);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

	public void ejecutar() throws Exception
	{
		boolean terminar = false;

		welcomeSocket = new ServerSocket(8976);
		System.out.println("Servidor en linea...");

		while (!terminar) {


			try {
				SocketManager sm = new SocketManager(welcomeSocket.accept());
				Runnable nuevoCliente = new GestorServidor(sm); 
				Thread hilo = new Thread(nuevoCliente);
				hilo.start();
			}
			catch ( Exception excepcionClaseNoEncontrada ) {
				terminar = true;
			}
		}
	}
}